package com.sunda.spmsweb.ibmmq;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.jms.core.JmsOperations;
import org.springframework.stereotype.Component;

import java.util.UUID;

/**
 * @program: ibmmq
 * @description: SendMessage
 * @author: Wayne Wu
 * @create: 2020-07-14 13:29
 **/
@Component
@Slf4j
public class SendMessage {
    @Autowired
    @Qualifier(value = "PIN_OUT3")
    JmsOperations jmsOperations;

    //@PostConstruct在服务器加载Servlet的时候运行，并且只会被服务器执行一次, @PreDestroy在destroy()方法执行执行之后执行
//    @PostConstruct
    public void sendOneTime(){
//        String msg = "REQUEST:{" +
//                "ESB_ATTRS:{" +
//                "Application_ID:" + "00020000000004" +
//                ", Transaction_ID:" + UUID.randomUUID() +
//                "}," +
//                "REQUEST_DATA:{" +
//                "reqAppId:" + "GH01" +
//                ", rfcName:" + "Z_RFC_STORE_09_IT" +
//                ", date:" + "2020-11-03" +
//                ", tableName:" + "" +
//                ", isSyn:" + "0" +
//                "}" +
//                '}';

        String msg = "{\"REQUEST\":{\"ESB_ATTRS\":{\"Application_ID\":\"00020000000004\"," +
                "\"Transaction_ID\":" + "\"" + UUID.randomUUID() + "\"" +
                "},\"REQUEST_DATA\":{\"reqAppId\":\"SPMS\",\"rfcName\":\"Z_RFC_STORE_09\"," +
                "\"date\":\"\",\"tableName\":\"\",\"isSyn\":\"0\"}}}";
        try {
            log.info("========= sendOneTime 开始发送消息......");
            jmsOperations.convertAndSend(JmsConfigOut.queue, msg);
            log.info("========= sendOneTime 发送队列消息成功\n");
        }catch (Exception e){
            log.info("========= sendOneTime 发送队列消息错误: " + e);
        }
    }


}